const baseDataToSend = {
  code: 0,
  type: "Data",
  companyId: 77,
  districtId: 41,
  siteId: 67,
  gatewayId: 51,
  data: [
    {
      deviceId: 332,
      cabinetId: 143,
      indicatorData: [
        {
          id: 1,
          value: 101
        },
        {
          id: 2,
          value: 102
        },
        {
          id: 3,
          value: 103
        },
        {
          id: 4,
          value: 104
        },
        {
          id: 5,
          value: 105
        }
      ]
    }
  ]
};

const WebSocketClient = require('websocket').client;
const client = new WebSocketClient();
client.connect('ws://localhost:8080/ws/receive');

client.on('connectFailed', function (error) {
  console.log('Connect Error: ' + error.toString());
});


client.on('connect', function (connection) {
  console.log('WebSocket Client Connected');
  if (connection.connected) {
    connection.sendUTF(JSON.stringify(baseDataToSend));
    console.log('send');
  }
  connection.on('error', function (error) {
    console.log("Connection Error: " + error.toString());
  });
  connection.on('close', function () {
    console.log('echo-protocol Connection Closed');
  });
  connection.on('message', function (message) {
    if (message.type === 'utf8') {
      console.log("Received: '" + message.utf8Data + "'");
    }
  });
});
